from typing import List


class Solution:
    def maxDistance(self, nums1: List[int], nums2: List[int]) -> int:
        i, j, ans = 0, 0, 0
        while i < len(nums1):
            while j < len(nums2) and nums2[j] >= nums1[i]:
                j += 1
            ans = max(ans, j - i - 1)
            i += 1

        return ans